<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div id="box">
        <com1 @geta='handleA'></com1>
        <com2 :data='pMsg'></com2>
    </div>
    <script>
        Vue.component("com1", {
            template: `
            <div @click='handleToClick'>this is com1</div>
            `,
            data() {
                return {
                    str: '这是com1的数据'
                }
            },
            methods: {
                handleToClick() {
                    this.$emit('geta', this.str)
                }
            }
        })
        Vue.component("com2", {
            template: `
            <div>this is com2{{data}}</div>
            `,
            props: ['data'],
            data() {
                return {
                    str: '这是com2的数据'
                }
            },
            methods: {

            }
        })
        var vm = new Vue({
            el: "#box",
            data: {
                pMsg: '',
            },
            methods: {
                handleA(datas) {
                    this.pMsg = datas
                }
            }
        })
    </script>
</body>

</html>